{% extends "mobile/base.html" %}
{% from "layout/errorlist.html" import errorlist %}
{% from "questions/includes/aaq_macros.html" import select_product, selected_product, select_category, selected_category %}
{% from "questions/includes/aaq_macros.html" import current_articles_and_message, aaq_search_form with context %}
{% set title = _('Ask A Question') %}
{% set headline = title %}
{% set classes = 'aaq' %}
{% if form %}
  {% set classes = classes + ' question-form' %}
  {% set return_url = url('questions.aaq_step3', product_key=current_product.key, category_key=current_category.key) %}
{% endif %}
{% if not tried_search and (current_articles or current_html) and not search_results and not form %}
  {% set return_url = url('questions.aaq_step2', product_key=current_product.key) %}
{% endif %}
{% set styles = ('mobile-aaq',) %}
{% set scripts = ('mobile-aaq',) %}
{% set hide_locale_switcher = True %}
{% set meta = [('robots', 'noindex')] %}

{% block content %}
  {% if not current_category %}
    <div class="filter-bar">
      <h2>{{ _('Products') }}</h2>
      <div id="product-switcher" class="swipeable">
        <ul>
          {% for key, product in products.iteritems() %}
            <li class="{% if product == current_product %}selected{% endif %}">
              <a href="{{ url('questions.aaq_step2', product_key=key) }}" data-event-category="link click"
              data-event-action="product" data-event-label="{{ product.name }}">
                  {% if key == 'other' %}
                      <span class="logo"
                          style="background-image: url({{ static('sumo/img/dino-logo.png') }})">
                    </span>
                  {% else %}
                  <span class="logo"
                      style="background-image: url({{ image_for_product(product.product) }})">
                  </span>
                  {% endif %}
                {{ product.name }}
              </a>
            </li>
          {% endfor %}
        </ul>
      </div>
    </div>
  {% endif %}

  {% if not current_product %}
    {{ select_product(products) }}
  {% endif %}

  {% if current_product and not current_category and current_product.categories %}
    {{ select_category(current_product) }}
  {% endif %}

  {% if not tried_search and (current_articles or current_html) and not search_results and not form %}
    {{ current_articles_and_message(current_articles, current_category, current_html) }}
    <div class="try_or_post {% if deadend %}deadend{% endif %} cf">
      <a class="btn" href="{{ url('questions.aaq_step2', product_key=current_product.key) }}">{{ _('Try another topic') }}</a>

      {% if not deadend %}
        {% set next_step_url = url('questions.aaq_step5', product_key=current_product.key, category_key=current_category.key) %}
        <form action="{{ next_step_url }}" method="get">
          <input type="hidden" name="search" value="{{ request.GET.search }}" />
          <input type="hidden" name="step" value="{% if user.is_authenticated() %}aaq-question{% else %}aaq-register{% endif %}" />
          <button type="submit" class="btn">{{ _('Post a question') }}</button>
        </form>
      {% endif %}
    </div>
  {% endif %}

  {% if form %}
    <form id="question-form" action="" method="post">
      {% csrf_token %}
      {{ errorlist(form) }}
      {% for field in form.hidden_fields() %}
        {{ field|safe }}
      {% endfor %}
      <ol>
        {% for field in form.visible_fields() %}
          <li class="field-{{ field.name }} {% if field.errors %}invalid{% endif %}">
            {{ field.label_tag()|safe }}
            {{ field|safe }}
          </li>
        {% endfor %}
        <li class="submit">
          <button type="submit" class="btn btn-submit">{{ _('Next') }}</button>
        </li>
      </ol>
    </form>
  {% endif %}
{% endblock %}
